<?php

namespace app\http\middleware;

use app\admin\model\User;
use think\facade\Url;
use think\response\Json;


class Auth
{
    public function handle($request, \Closure $next)
    {
        //验证登录
        if ((new User())->isLogin()==false) {
            if ($request->isAjax()){
                return Json::create(['code'=>0,'msg'=>'用户未认证','url'=>Url::build('admin/login/index')]);
            }else{
                return redirect('admin/login/index');
            }
        }
        return $next($request);
    }
}
